<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>

<?php
$attributes = array(
    'class' => 'control-label',
);
?>

<div class="span9">

    <h2><?php echo $titulo; ?></h2>

    <?php echo get_message(); ?>

    <?php echo form_open(); ?>

    <div class="row-fluid">
        <div class="span6">
            <div class="control-group">
                <?php echo form_label('Banco', 'bancoId', $attributes); ?>
                <div class="controls">
                    <?php
                    echo form_dropdown('bancoId', $bancos, $pago['bancoId'], 'class="span11" id="bancoId"');
                    ?>
                </div>
            </div>
            <div class="control-group">
                <?php echo form_label('Fecha', 'fecha', $attributes); ?>
                <div class="controls input-append">
                    <?php
                    echo form_input(array('class' => 'span8 date-picker', 'data-date-format' => 'dd/mm/yyyy', 'name' => 'fecha', 'type' => 'text', 'value' => $pago['fecha']));
                    ?><span class="add-on"><i class="icon-calendar"></i></span>
                </div>
            </div>
            <div class="control-group">
                <?php echo form_label('Número de Cheque', 'nroCheque', $attributes); ?>
                <div class="controls">
                    <?php echo form_input(array('class' => 'span11', 'name' => 'nroCheque', 'type' => 'text', 'value' => $pago['nroCheque'])); ?>
                </div>
            </div>
            <div class="control-group">
                <?php echo form_label('Número de Comprobante de Pago', 'nroCptePago', $attributes); ?>
                <div class="controls">
                    <?php echo form_input(array('class' => 'span11', 'name' => 'nroCptePago', 'type' => 'text', 'value' => $pago['nroCptePago'])); ?>
                </div>
            </div>
        </div>

        <div class="span6">
            <div class="control-group">
                <?php echo form_label('Concepto', 'conceptoId', $attributes); ?>
                <div class="controls">
                    <?php
                    echo form_dropdown('conceptoId', $conceptos, $pago['conceptoId'], 'class="span11" id="conceptoId"');
                    ?>
                </div>
            </div>
            <div class="control-group">
                <?php echo form_label('Beneficiario', 'beneficiario', $attributes); ?>
                <div class="controls">
                    <?php echo form_input(array('class' => 'span11', 'name' => 'beneficiario', 'type' => 'text', 'value' => $pago['beneficiario'])); ?>
                </div>
            </div>
            <div class="control-group">
                <?php echo form_label('Moneda', 'moneda', $attributes); ?>
                <div class="controls">
                    <?php
                    echo form_dropdown('moneda', $moneda, $pago['moneda'], 'class="span11" id="moneda"');
                    ?>
                </div>
            </div>
            <div class="control-group">
                <?php echo form_label('Importe', 'importe', $attributes); ?>
                <div class="controls">
                    <?php echo form_input(array('class' => 'span11', 'name' => 'importe', 'type' => 'text', 'value' => $pago['importe'])); ?>
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <?php echo form_input(array('class' => 'span11', 'name' => 'submit', 'type' => 'submit', 'value' => 'Guardar', 'class' => 'btn')); ?>
                    <button type="button" onclick="window.location = '<?php echo base_url('subsidios'); ?>';" class="btn">Cancelar</button>
                </div>
            </div>
        </div>
    </div>

    <hr/>

    <table id="beneficiarios" class="table-striped" style="width: 100%">
        <thead>
            <tr>
                <th style="width: 10%;">Nro. Causa</th>
                <th style="width: 20%;">Carátula</th>
                <th style="width: 10%;">Nro. Exp.</th>
                <th style="width: 10%;">Matrícula</th>
                <th style="width: 20%;">Nombre</th>
                <th style="width: 10%;">Nro. Doc.</th>
                <th style="width: 10%;">Importe</th>
                <th style="width: 10%;">Acciones</th>
            </tr>
        </thead>
        <?php
        if (!empty($pago['beneficiarios'])) {
            foreach ($pago['beneficiarios'] as $beneficiario) {
                ?>
                <tr id="<?php echo $beneficiario->id; ?>-eliminar">
                    <td><?php echo $beneficiario->causaId; ?></td>
                    <td><?php echo $beneficiario->caratula->nombre; ?></td>
                    <td><?php echo $beneficiario->caratula->nroExpediente; ?></td>
                    <td><?php echo $beneficiario->matricula; ?></td>
                    <td><?php echo $beneficiario->nombre; ?></td>
                    <td><?php echo $beneficiario->numeroDoc; ?></td>
                    <td><input type="text" name="importes[]" class="span11" value="<?php echo $beneficiario->importe; ?>" /><input type="hidden" name="beneficiarios[]" value="<?php echo $beneficiario->id; ?>" /></td>
                    <td><a class="btn btn-small borrar" href="#borrar" role="button" data-toggle="modal" dbid="<?php echo $beneficiario->id; ?>"><span class="icon-remove"></span> Borrar</a></td>
                </tr>
                <?php
            }
        }
        ?>
    </table>

    <hr/>

    <p><button class="btn" type="button" onclick="javascript:nuevo();"><i class="icon-search"></i> Buscar y agregar Profesionales</button></p>

    <?php echo form_close(); ?>

</div>


<?php echo form_hidden('idBeneficiario', ''); ?>

<script type="text/javascript">
    $(".borrar").live('click',function(){
        $('input[name=idBeneficiario]').val($(this).attr('dbid'));
        $('#eliminar').modal('show');
    });
    
    $('#confirmaeliminacion').live('click', function(){
        var id = $('input[name=idBeneficiario]').val();
        $('#' + id + '-eliminar').hide('fast');
        $('#' + id + '-eliminar').remove();

        $('#borrar').modal('hide');
    });
    
    var popup;
    function nuevo(){
        popup = window.open("<?php echo base_url('subsidios/buscar'); ?>","miwin","left=200,top=50,width=960,height=500,scrollbars=yes");
        popup.focus();
    }
</script>

<div class="modal toggle fade" id="borrar" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Eliminar</h3>
    </div>
    <div class="modal-body">
        <p>¿Está seguro?</p>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">No</button>
        <button id="confirmaeliminacion" class="btn btn-primary">Si</button>
    </div>
</div>